/* This program creates the graph in Figure 2.

*/





***************************************
*** Figure 2: Corp Pats Event Study ***
***************************************
use ${output_data}corppats_regdata.dta, clear

destring fips, gen(numfips)

local infile ${output_data}corppats_regdata.dta

local indvar  allcites1980 
local depvar lnpatcount 


foreach dep in `depvar' {
	foreach var in `indvar' {
		use `infile', clear

        destring fips, gen(numfips)

		reghdfe `dep' xz`var'I*  z`var' if year>1974 & year<=2002,  absorb(uspto#year numfips#year uspto#numfips) vce(cluster numfips) 
	
		gen graphbeta=.
		gen graphlci=.
		gen graphuci=.
		gen runtime=.
		foreach i in 1977 1978 1979 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997  {
			replace graphbeta=_b[xz`var'I`i']  in `=`i'-1976'
			replace graphlci=(_b[xz`var'I`i']  -1.96* abs(_se[xz`var'I`i'])) in `=`i'-1976'
			replace graphuci=(_b[xz`var'I`i']  +1.96* abs(_se[xz`var'I`i'])) in `=`i'-1976'
			replace runtime= `=`i'' in `=`i'-1976'
		}
		replace graphbeta = 0 in 4
		replace graphlci = 0 in 4
		replace graphuci = 0 in 4
		replace runtime = 1980 in 4
	
	sort runtime
	
		if "`dep'"=="lnpatcount" {
			twoway (connected graphbeta runtime if runtime>=1977 & runtime<1980, mcolor(black)  lcolor(black)) (connected graphbeta runtime if runtime>1978 & runtime<1981, mcolor(black)  lcolor(black))	(connected graphbeta runtime if runtime>=1980, mcolor(black)  lcolor(black)) (rcap graphuci graphlci runtime if runtime>=1977 & runtime<=1997, msymbol(dot) mcolor(gray) lcolor(navy) lp(dash) lwidth(medium)) ,  xline(1980.5,  lp(dash)) yline(0, lc(gs2))  ytick(, grid) xlabel(1977(2)1997) plotregion(margin(0)) legend(off) graphregion(color(white)) bgcolor(white) xtit("Year") ytit("Log Patents")		
		}
		
		else if "`dep'"=="lnhjtimp" {
			twoway (connected graphbeta runtime if runtime>=1977 &  runtime<1980, mcolor(black)  lcolor(black)) (connected graphbeta runtime if runtime>1978 & runtime<1981, mcolor(black)  lcolor(black))	(connected graphbeta runtime if runtime>=1980, mcolor(black)  lcolor(black)) (rcap graphuci graphlci runtime if runtime>=1978 & runtime<=2002, msymbol(dot) mcolor(gray) lcolor(navy) lp(dash) lwidth(medium))  ,  xline(1980.5, lp(dash)) yline(0, lc(gs2))  ytick(, grid) xlabel(1977(2)1997) plotregion(margin(0)) legend(off) graphregion(color(white)) bgcolor(white) xtit("Year") ytit("Log Citation-Weighted Patents")		
		}
		
		
		graph export ${graphs}`dep'_`var'_iycyicFE.eps, replace
		!epstopdf ${graphs}`dep'_`var'_iycyicFE.eps


	}
}

*******************
** END Figure 2 ***
*******************

